<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

      //用函数封装一个字符串的substr方法  
        //字符串截取  截取从n开始m个字符

        var str = "qwertyuiop";
        var n = 2;
        var m = 5;

        //var str1 = str[2]+str[3]+str[4]+str[5]+str[6];
        //console.log("str1",str);

        //var str1 = "";
        //for (var i=n;i<n+m;i++) {
          //  str1+=str[i]
          //}


        function substr2(string, n ,m) {
            if(!m) m = string.length-n;
            var str1 = "";
            for(vari=n;i<n+m; i++) {
                str += string[i]
            }
            return str1;
        }
        //var s= substr2(str,2);
        //console.log(5);

        Srting.prototype.substr3 =function(n,m) {
            if(!m)m= this.length-n;
            var str1 = "";
            for(var i = n;i<n+m; i++) {
                str1 +=this[i]
            }
            return str1
        }

    </script>
</body>
</html>